﻿/// <reference path="../Scripts/qunit.js" />
/// <reference path="KataBinaryClock.js" />

module("Date methods");

test('getHours', function () {
  var date = new Date(2012, 6, 15, 23, 45, 12);
  equal(date.getHours(), 23, 'test getHours() returns 23');
});

test('getMinutes', function () {
  var date = new Date(2012, 6, 15, 23, 45, 12);
  equal(date.getMinutes(), 45, 'test getMinutes() returns 45');
});

test('getSeconds', function () {
  var date = new Date(2012, 6, 15, 23, 45, 12);
  equal(date.getSeconds(), 12, 'test getSeconds() returns 12');
});

module("KataBinaryClock I");

test('getBits', function () {
  // use deepEqual in order to compare arrays
  deepEqual(getBits(0), new Array(0, 0, 0, 0), 'test getBits(0) returns 0000');
});

test('getBits', function () {
  // use deepEqual in order to compare arrays
  deepEqual(getBits(1), new Array(0, 0, 0, 1), 'test getBits(0) returns 0001');
});

test('getBits', function () {
  // use deepEqual in order to compare arrays
  deepEqual(getBits(2), new Array(0, 0, 1, 0), 'test getBits(0) returns 0010');
});

test('getBits', function () {
  // use deepEqual in order to compare arrays
  deepEqual(getBits(3), new Array(0, 0, 1, 1), 'test getBits(0) returns 0011');
});

module("KataBinaryClock II", {
  setup: function () {
    this.date = new Date(2012, 6, 15, 23, 45, 12);
  }
});

test('dateToString', function () {
  deepEqual(dateToString(this.date), '234512', 'dateToString returns "234512"');
});

test('dateToString', function () {
  deepEqual(dateToString(new Date(2012, 6, 15, 6, 5, 4)), '060504', 'dateToString returns "060504"');
});

module("KataBinaryClock III", {
  setup: function () {
    this.date = new Date(2012, 6, 15, 23, 45, 12);
  }
});

test('stringToArrayOfIntegers', function () {
  var string = dateToString(this.date);
  deepEqual(stringToArrayOfIntegers(string), new Array(2, 3, 4, 5, 1, 2), 'this.date returns "Array(2, 3, 4, 5, 1, 2)"');
});

test('BinaryClock (before)', function () {
  var string = dateToString(this.date);
  var digits = stringToArrayOfIntegers(string);
  var binaries = new Array();
  for (var i = 0; i < digits.length; i++) {
    binaries.push(getBits(digits[i]));
  }
  deepEqual(binaries[0], new Array(0, 0, 1, 0), 'test binaries[0] is equal to 0010');
  deepEqual(binaries[1], new Array(0, 0, 1, 1), 'test binaries[1] is equal to 0011');
  deepEqual(binaries[2], new Array(0, 1, 0, 0), 'test binaries[2] is equal to 0100');
  deepEqual(binaries[3], new Array(0, 1, 0, 1), 'test binaries[3] is equal to 0101');
  deepEqual(binaries[4], new Array(0, 0, 0, 1), 'test binaries[4] is equal to 0001');
  deepEqual(binaries[5], new Array(0, 0, 1, 0), 'test binaries[5] is equal to 0010');
});

test('BinaryClock (after)', function () {
  var binaryClock = new BinaryClock();
  var binaries = binaryClock.getBinaries(this.date);
  deepEqual(binaries[0], new Array(0, 0, 1, 0), 'test binaries[0] is equal to 0010');
  deepEqual(binaries[1], new Array(0, 0, 1, 1), 'test binaries[1] is equal to 0011');
  deepEqual(binaries[2], new Array(0, 1, 0, 0), 'test binaries[2] is equal to 0100');
  deepEqual(binaries[3], new Array(0, 1, 0, 1), 'test binaries[3] is equal to 0101');
  deepEqual(binaries[4], new Array(0, 0, 0, 1), 'test binaries[4] is equal to 0001');
  deepEqual(binaries[5], new Array(0, 0, 1, 0), 'test binaries[5] is equal to 0010');
});
